﻿@{
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}

@model ContractOutput
@using lwzlz.Core;
@{
    var memberList = ViewData["MemberList"] as List<MemberOutput>;
}


    <form class="layui-form layui-form-pane">
        @Html.AntiForgeryToken()
        <input type="hidden" value="@Model.Id" name="Id" />
        <input type="hidden" value="@Model.Code" name="Code" />
        <div class="layui-form-item">
            <label class="layui-form-label">加盟校账户</label>
            <div class="layui-input-block">
                <select name="MemberId" lay-search lay-filter="MemberId" id="MemberId" lay-verify="required">
                    <option value=""></option>
                    @{
                        foreach (var item in memberList)
                        {
                            <option value="@item.Id" @(Model.MemberId == item.Id ? "selected" : "")>@item.SchoolName (@item.UserName)</option>

                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">合同名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="Name" value="@Model.Name" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-block">
                <input type="text" name="StartTime" value="@(Model.StartTime!=null?  Convert.ToDateTime(Model.StartTime).ToString("yyyy-MM-dd"):"")" class="layui-input" id="StartTime" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-block">
                <input type="text" name="EndTime" value="@(Model.EndTime!=null?  Convert.ToDateTime(Model.EndTime).ToString("yyyy-MM-dd"):"")" class="layui-input" id="EndTime" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加盟金额</label>
            <div class="layui-input-block">
                <input type="number" class="layui-input" name="JoinMoney" value="@Model.JoinMoney" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账户数量</label>
            <div class="layui-input-block">
                <input type="number" class="layui-input" name="Number" value="@Model.Number" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌年费</label>
            <div class="layui-input-block">
                <input type="number" class="layui-input" name="BrandFee" value="@Model.BrandFee" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item" align="center">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="Save">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" id="btnCancel">取消</button>
        </div>
    </form>

@section scripts{
    <script type="text/javascript">
        var $, layer;
        layui.use(['form', 'laydate'], function () {
            var form = layui.form;
            var laydate = layui.laydate;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;

            //日期时间范围
            laydate.render({
                elem: '#StartTime'
            });

            //日期时间范围
            laydate.render({
                elem: '#EndTime'
            });

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });


            var postUrl = '@(Url.Action(Model.Id > 0 ? "Edit" : "Add", "Contract"))';

            // 监听提交
            form.on('submit(Save)', function (data) {
                var loading = layer.load();
                $.post(postUrl, data.field,
                    function (result) {
                        layer.close(loading);
                        if (result.Success) {
                            layer.msg(result.Message, { icon: 1, time: 2000 });
                            parent.reload();
                            layer_close();
                        } else {
                            layer.alert(result.Message, { icon: 2 });
                        }
                    });
                return false;
            })

        });
    </script>
}



